package com.gf.event.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.gf.base.type.Activity;
import com.gf.base.type.EventType;
import com.gf.common.util.DateFormater;
import com.gf.event.model.Event;

public class EventMapper implements RowMapper<Event> {

	private final static String COLUME_ID = "id";
	private final static String COLUME_USERID = "userId";
	private final static String COLUME_USERNAME = "userName";
	private final static String COLUME_OPERATION = "operation";
	private final static String COLUME_TITLE = "title";
	private final static String COLUME_TARGETID = "targetId";
	private final static String COLUME_EVENTTYPE = "eventType";
	private final static String COLUME_CREATETIME = "createtime";
	private final static String COLUME_ACTIVITY = "activity";
	private final static String COLUME_PORTRAIT = "portrait";
	private static final EventMapper mapper = new EventMapper();
	
	
	public static final EventMapper getMapper(){
		return mapper;
	}
	
	@Override
	public Event mapRow(ResultSet set, int row) throws SQLException {
		Event event = new Event();
		event.setPortrait(set.getString(COLUME_PORTRAIT));
		event.setId(set.getLong(COLUME_ID));
		event.setUserId(set.getLong(COLUME_USERID));
		event.setUserName(set.getString(COLUME_USERNAME));
		event.setOperation(set.getString(COLUME_OPERATION));
		event.setTitle(set.getString(COLUME_TITLE));
		event.setTargetId(set.getLong(COLUME_TARGETID));
		event.setEventType(EventType.valueOf(set.getString(COLUME_EVENTTYPE)));
		event.setCreatetime(set.getTimestamp(COLUME_CREATETIME));
		event.setActivity(Activity.valueOf(set.getString(COLUME_ACTIVITY)));
		event.setFormatTime(DateFormater.changeToString(set.getTimestamp(COLUME_CREATETIME), "yyyy-MM-dd HH:mm"));
		return event;
	}

}
